//e
#Title[Tv3]
#Text[]
#Image[]
#BGM[]
#Player[FREE]
#PlayLevel[]
#BackGround[]
#ScriptVersion[2]

script_enemy_main {

    // ֐̎荞
    #include_function ".\usershot\lib_usershot.txt"	// ew萔ǂݍ
    #include_function ".\effectdata\Obj_EffectALL.txt"	// GtFNg֐ꊇǂݍ

    // XNvg܂ł̃pX̎擾
    let csd        = GetCurrentScriptDirectory();

    // G摜̃pX
    let imgBoss    = csd ~ "img\ExRumia.png";

    // G̖O摜̃pX
    let ename      = csd ~ "img\ename.png";

    // ʒu̐ݒ
    let xIni       = GetCenterX()  + 1;
    let yIni       = GetClipMinY() + 120;

    // e摜̃pX
    let shotData   = csd ~ "\usershot\data_usershot.txt";

    @Initialize {

	LoadGraphic(imgBoss);
	SetTexture(imgBoss);

	CutIn(YOUMU, "uv", "", 0, 0, 0, 0);

	SetLife(200);
	SetTimer(60);
	SetScore(10000000/3);
	SetDamageRate(0,0);

	DrawTimer();				// c莞Ԃ̕\
	DrawTimerEx(1);				// c莞Ԃ̕\
	EnemyMarker01();			// Gl~[}[J[̕\
	LifeBar_A_02(3, 0.2, 0.0, false);	// ԃQ[W̕\

	LifeStock(0,true);			// cXyJ[h̕\
	LifeCircleBar_A(0.2, 0.0, false);	// 3{ڂ̉~Q[W̕\

	DrawEnemyName(ename,0,16,false);	// G̖O̕\
	Aura1(8, 64, 64,128);			// I[̕\1
	Aura2(0,160, 64, 64);			// I[̕\2
	MagicCircleEx2(false);			// @w̕\

	MagicCircle(false);
	SetRateScoreSystemEnable(false);
	LoadUserShotData(shotData);
	SetEffectForZeroLife(0, 0, 0);
	SetShotAutoDeleteClip(32, 32, 32, 32);

	MainTask();

    }

    @MainLoop {
	SetCollisionA(GetX, GetY, 32);
	SetCollisionB(GetX, GetY, 32);

	yield;
    }

    @DrawLoop {
	DrawGraphic(GetX, GetY);
    }

    @Finalize {
	DeleteGraphic(imgBoss);
    }

    // C^XN
    task MainTask {

	yield;

	StandBy();
	Shot();
	wait(240);
	loop {
	    Move();
	    wait(60);
	}

    }

    // ʒuֈړ
    function StandBy {
	SetMovePositionRandom01(416, 464, 5, xIni, yIni, xIni, yIni);
	SetGraphicMove();
	wait(60);
	SetGraphicStop();
	wait(60);
	SetDamageRate(10,0);
	SetGraphicPose();
    }

    // ړ
    function Move {
	SetMovePositionRandom01(100, 10, 3, xIni-120, yIni-30, xIni+120, yIni+30);
	SetGraphicMove();
	wait(60);
	SetGraphicStop();
    }

    // U
    task Shot {

	let way      = 4;			// e
	let long     = 10;			// G̋
	let speed    = 3;			// x
	let angle    = 180;			// 1ڂ̊px
	let addangle = 0;			// px
	let addspeed = 0;			// x
	let maxspeed = 0;			// ōx(Œᑬx)
	let delay    = 12;			// x

	let eff     = dPURPLE01;		// GtFNg̒萔(ID)
	let graphic = US_RICE_S_PURPLE;		// e摜̒萔
	let bomb    = false;			// {ϐ
	let time    = 0;			// RŎ

	let count   = 45;

	loop {
	    loop(way) {
		CreateObjShotC_T04(GetX()+long*cos(angle), GetY()+long*sin(angle), speed, angle, addangle, addspeed, maxspeed, graphic, eff, delay, time, bomb);
		angle += 360 / way;
	    }
	    wait(1);
	    angle = 1440 * sin(count);
	    count += 0.75;
	    if(GetTimer<39){
		eff = dPURPLE13;
		graphic = US_RICE_M_PURPLE;
	    }
	}
    }

    // OtBbN̐ݒ
    sub SetGraphicStop  { SetGraphicRect(  0,  0, 64, 64); }
    sub SetGraphicPose  { SetGraphicRect( 64,  0,128, 64); }
    sub SetGraphicLeft  { SetGraphicRect(128,  0,192, 64); }
    sub SetGraphicRight { SetGraphicRect(192,  0,256, 64); }

    sub SetGraphicMove {
	if(GetSpeedX <  0) { SetGraphicLeft(); }
	else { SetGraphicRight(); }
    }

    // w t[ҋ@
    function wait(w) { loop(w){ yield; } }

}